// pages/community/activity/activity.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    images: [],
    list: [{
      id: '0',
      title: '平凡',
      desc: '相机将平凡的感到与最美好的爱，定格在那一个瞬间。。。。。。',
      time: '2016.10.25 07:51',
      userLogo: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/userLogoImg.png',
      pictureDetails: [{
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg1.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg2.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg3.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg4.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg5.png'
      }],
      applaud: {
        status: false,
        num: 89
      },
      comment: {
        status: false,
        num: 14
      },
      collection: {
        status: false,
        num: 25
      }
    }, {
      id: '1',
      title: '平凡',
      desc: '相机将平凡的感到与最美好的爱，定格在那一个瞬间。。。。。。',
      time: '2016.10.25 07:51',
      userLogo: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/userLogoImg.png',
      pictureDetails: [{
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg1.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg2.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg3.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg4.png'
      }, {
        url: 'https://app-1256684088.cos.ap-beijing.myqcloud.com/wujieImages/communtityActivityImg5.png'
      }],
      applaud: {
        status: false,
        num: 89
      },
      comment: {
        status: false,
        num: 14
      },
      collection: {
        status: false,
        num: 25
      }
    }],

  },
  // 发布评论跳转
  addComment: function () {
    wx.navigateTo({
      url: '../addComment/addComment'
    })
  },
  // 前往商品详情
  toArticleDetails: function () {
    wx.navigateTo({
      url: '../articleDetails/articleDetails'
    })
  },
  /**
   * 图片根据高度自适应
   */
  heightFix: function (e) {
    var that = this;
    var width = e.detail.width, //获取图片真实宽度
      height = e.detail.height,
      ratio = width / height; //图片的真实宽高比例
    var viewHeight = 225, //设置图片显示宽度，
      viewWidth = viewHeight * ratio; //计算的高度值   
    var image = this.data.images;
    //将图片的datadata-index作为image对象的key,然后存储图片的宽高值
    console.log(e.target.dataset.index)
    image[e.target.dataset.index] = {
      width: viewWidth,
      height: viewHeight
    }
    this.setData({
      images: image
    })
  },

  /**
   * 点赞
   */
  clickApplaud: function (e) {
    const that = this
    const id = e.currentTarget.dataset.id
    let tempList = this.data.list
    tempList.forEach(item => {
      if (item.id === id) {
        if (item.applaud.status) {
          item.applaud.status = false
          item.applaud.num--
        } else {
          item.applaud.status = true
          item.applaud.num++
        }
      }
    })
    that.setData({
      list: tempList
    })
  },

  /**
   * 收藏
   */
  clickCollection: function (e) {
    const that = this
    const id = e.currentTarget.dataset.id
    let tempList = this.data.list
    tempList.forEach(item => {
      if (item.id === id) {
        if (item.collection.status) {
          item.collection.status = false
          item.collection.num--
        } else {
          item.collection.status = true
          item.collection.num++
        }
      }
    })
    that.setData({
      list: tempList
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})